Array.prototype.remove = function(val) {
    var index = this.indexOf(val);
    if (index > -1) {
        this.splice(index, 1);
    }
};

// URL
function url(path) 
{
    var host = window.location.protocol + '//' + location.hostname;

    if ((typeof(path) == "undefined") || (path == '') || (path == '/')) {
        return host;
    }

    if (path[0] == '/' && path[path.length-1] == '/') {
        path = path.slice(1,-1);
    } else if (path[0] == '/') {
        path = path.slice(1);
    } else if (path[path.length-1] == '/') {
        path = path.slice(0, -1);
    }

    return host + '/' + path;
}

Date.prototype.Format = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "h+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

function get(name) {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return unescape(r[2]);
    }
    return null;
}

// 全选
$(".checkbox-all[type='checkbox']").on('change', function() {
    $(".checkbox-item[type='checkbox']").prop('checked', $(this).prop('checked'));
    $(".checkbox-all[type='checkbox']").prop('checked', $(this).prop('checked')); 

    if ($(".checkbox-item[type='checkbox']:checked").length > 0) {
        $('.selected-items').removeClass('disabled');
    } else {
        $('.selected-items').addClass('disabled');
    }
});

$(".checkbox-item[type='checkbox']").on('change', function() {
    var length = $(".checkbox-item[type='checkbox']:checked").length;
    var allLength = $(".checkbox-item[type='checkbox']").length;

    $(".checkbox-all[type='checkbox']").prop('checked', length == allLength);

    if (length > 0) {
        $('.selected-items').removeClass('disabled');
    } else {
        $('.selected-items').addClass('disabled');
    }
});

// json求和
function jsonSum(object)
{
    var sum = 0;
    for(var item in object) {
        sum += item
    }

    return sum;
}